/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.mvc.view;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.View;

/**
 * Spring {@link View} that just returns an error code.
 */
public class ErrorCodeView
    implements View
{

  /**
   * the error status to return to the user.
   */
  private int status;



  /**
   * returns the content type of the view, if predetermined.
   * 
   * @return the content type String (optionally including a character set), or
   *         null if not predetermined
   * @see org.springframework.web.servlet.View#getContentType()
   */
  public String getContentType()
  {
    return null;
  }



  /**
   * render the view given the specified model.
   * <p>
   * The first step will be preparing the request: In the JSP case, this would
   * mean setting model objects as request attributes. The second step will be
   * the actual rendering of the view, for example including the JSP via a
   * RequestDispatcher.
   * 
   * @param model
   *          {@link Map} with name Strings as keys and corresponding model
   *          objects as values (map can also be null in case of empty model)
   * @param request
   *          current HTTP request
   * @param response
   *          current HTTP response
   * @throws IOException
   *           when an error occured
   * @see org.springframework.web.servlet.View#render(java.util.Map,
   *      javax.servlet.http.HttpServletRequest,
   *      javax.servlet.http.HttpServletResponse)
   */
  public void render(@SuppressWarnings("unchecked")
  Map model, HttpServletRequest request, HttpServletResponse response)
      throws IOException
  {
    response.sendError(getStatus());
  }



  /**
   * getter for the status property.
   * 
   * @return the status
   */
  public int getStatus()
  {
    return status;
  }



  /**
   * setter for the status property.
   * 
   * @param status
   *          the status to set
   */
  public void setStatus(int status)
  {
    this.status = status;
  }

}
